﻿#ifndef LOGQUEUE_H
#define LOGQUEUE_H

#include <QObject>
#include <QVector>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QFile>

#include <tuple>
#include <queue>

#define TEST_PATH           "E:/QT_Proj/spike3.05/SpectrumGRD/bin/log"

class LogQueue : public QObject
{
    Q_OBJECT
public:
    enum LogType {
        LogType_SoftRun = 1,
        LogType_Device,
        LogType_User,
        LogType_BGTrace,
        LogType_Alarm
    };

    LogQueue(QObject *parent = nullptr) : QObject(parent) {}
    ~LogQueue() { clear(); }

    bool loadLog(QDateTime beginDateTime, const QDateTime &endDateTime, const LogType type);

    size_t size() { return m_logQueue.size(); }

    void clear() { std::queue<std::tuple<QDate, QTime, QString, QString>> emtpy; std::swap(emtpy, m_logQueue); }

    std::tuple<QDate, QTime, QString, QString>& front(){ return m_logQueue.front(); }

    void popLog(){ m_logQueue.pop(); }

signals:
    void updateTable();

private:
    std::queue<std::tuple<QDate, QTime, QString, QString>> m_logQueue;

    bool judgeType(const QStringList &logStrList, const LogType type);
    /**@brief 格式化日志: 如果日志按空格分割后大于4, 则合成4个字符串 */
    QStringList getFormatLogTxt(const QStringList &logStrList) const;

};

#endif // LOGQUEUE_H
